package com.atguigu.tingshu.live.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.live.service.LiveRoomService;
import com.atguigu.tingshu.model.live.LiveRoom;
import com.atguigu.tingshu.vo.live.LiveRoomVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/live/liveRoom")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LiveRoomApiController {

	@Autowired
	private LiveRoomService liveRoomService;
	/**
	 * @description: 获取当前用户直播
	 * @author Petrichor
	 * @date 2024/1/12 20:47
	 * @return 直播房间
	**/
	@GuiGuLogin
	@Operation(summary = "获取当前用户直播")
	@GetMapping("getCurrentLive")
	public Result<LiveRoom> getCurrentLive() {
		return Result.ok(liveRoomService.getCurrentLive(AuthContextHolder.getUserId()));
	}
	/**
	 * @description: 创建直播
	 * @author Petrichor
	 * @date 2024/1/12 21:22
	 * @param liveRoomVo 直播间信息
	 * @return liveRoom
	**/
	@GuiGuLogin
	@Operation(summary = "创建直播")
	@PostMapping("saveLiveRoom")
	public Result<LiveRoom> saveLiveRoom(@RequestBody @Validated LiveRoomVo liveRoomVo) {
		return Result.ok(liveRoomService.saveLiveRoom(liveRoomVo, AuthContextHolder.getUserId()));
	}
	/**
	 * @description: 获取当前直播列表
	 * @author Petrichor
	 * @date 2024/1/12 21:26
	 * @return 当前直播列表
	**/
	@GuiGuLogin
	@Operation(summary = "获取当前直播列表")
	@GetMapping("findLiveList")
	public Result<List<LiveRoom>> findLiveList() {
		return Result.ok(liveRoomService.findLiveList());
	}
	/**
	 * @description: 根据id获取信息
	 * @author Petrichor
	 * @date 2024/1/12 21:29
	 * @param id 房间id
	 * @return 回显直播页面
	**/
	@GuiGuLogin
	@Operation(summary = "根据id获取信息")
	@GetMapping("getById/{id}")
	public Result<LiveRoom> getById(@PathVariable Long id) {
		return Result.ok(liveRoomService.getById(id));
	}
}

